package com.kaigejava.factorypattern.method;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by kaigejava on 2019/8/24.
 * 披萨订单顶级抽象类
 */
public abstract class PizzaOrderAbstract {

    public PizzaOrderAbstract(){
        //披萨对象
        PizzaAbstract pizza = null;
        //订单类型
        String orderType;
        do{
            orderType = getOrderType();
            pizza = createPizza(orderType);
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        }while (true);
    }

    /**
     * 根据披萨订单类型制作披萨
     * @param ordertype
     * @return
     */
    protected abstract PizzaAbstract createPizza(String ordertype);


    private String getOrderType() {

        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(
                    System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();

            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
